#include <stdio.h>
#include <string.h>
int nextarr(char str[],char next[],int len);
int main(){
	char s[] = "abcabcaca";
	char p[] = "abcac";
	int i = 0,j = 0;
	int len = strlen(p);
	char next[len -1];
	nextarr(p,next,len);
	next[0] = 0;
	while(j<=len-1){
		if(s[i] == p[j]){
			++i;
			++j;
		}else{
			i -= j-1;
			j = next[j];
		}
	}
	printf("%d\n",i - len);
	return 0;
}

int nextarr(char str[],char next[],int len){
	int i = 0,j = 1;
	while(j<=len-1){
		if(str[i] == str[j]){
			next[j] = j;
		}else{
			next[j] = 0;
			++j;
		}
	}
	return 0;
}